@echo OFF
echo XXXXXXXXXXXX dos grammer test XXXXXXXXXXXX
echo help: 
echo         del /?
echo         timeout /?
echo         for /?
@REM add empty line
echo=
echo+

@REM current path
echo fileName: %~0
echo path: %CD% | clip
echo cd %cd%
echo ~dp0: %~dp0
set currentPath=%cd%

@REM create a file named by datetime
set fileName=
set fileNameWithExt=
set str_time_first_bit="%time:~0,1%"
if %str_time_first_bit%==" " (
	set fileName=%date:~0,4%%date:~5,2%%date:~8,2%_0%time:~1,1%%time:~3,2%%time:~6,2%
) else (
	set fileName=%date:~0,4%%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2%%time:~6,2%
)
set fileNameWithExt=%fileName%.txt
echo %fileNameWithExt%
echo %fileName% > %fileNameWithExt%
echo;

@REM ~: remove ""
IF NOT EXIST %fileNameWithExt% (
    echo no %arg1% file error!
    pause
    exit
) else if "%arg1%"=="" (
    @REM if no arg
    echo arg is null
) else (
    set arg1=%~1
    echo %arg1%: %1
    echo %arg1%: "%~1"
)
echo.
echo,

echo for 1: read file %fileNameWithExt%
echo 1__zhangsan_hebei_22 >> %fileNameWithExt%
echo 2__lisi_shanghai_33 >> %fileNameWithExt%
echo 3__wangwu_nanjing_44 >> %fileNameWithExt%
for /f "eol=; tokens=2,3-4* delims=/\_ " %%i in (%fileNameWithExt%) do (
    echo %%k %%i %%j
)

echo/
echo for 2: split string
for /f "tokens=1-5 delims=_" %%a in ("aa_bb___2") do (
    echo %%a %%b %%c %%d
)
echo;
echo;

@REM :获取管理员权限
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)
@REM :保持当前目录下运行
cd /d "%~dp0"

@REM open desktop
for /f "tokens=2,*" %%i in ('reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Desktop"') do Set desktopPath=%%j
echo desktop path: %desktopPath%
cd /D %desktopPath%
timeout /t 2 /nobreak
@REM explorer %desktopPath%

@REM rem 下面是修改桌面路径
@REM set "a=D:\桌面"
@REM reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Desktop" /t REG_SZ /d %a%
@REM pause
@REM REM 获取管理员权限，弊端：需要输入密码
@REM REM runas /user:cuncaojin cmd
@REM REM 不关闭窗口
@REM @cmd /k

cd /D %currentPath%